﻿namespace LearnDSRecursions;

/// <summary>
/// Sum of N numbers
/// </summary>
public class SumOfNumbers
{
    public int Sumn(int n)
    {
        return n * (n + 1) / 2;
    }

    public int Sumniteration(int n)
    {
        int total = 0;
        int i = 1;
        while (i <= n)
        {
            total = total + i;
            i = i + 1;
        }

        return total;
    }

    public int SumnRecursion(int n)
    {
        if (n == 1)
            return 1;
        return SumnRecursion(n - 1) + n;
    }
}